setwd("/Volumes/Data/localDataNoBackup/sfer9710/Development/smfrgsn-devel/Loudness2/CodeProcessing/PlotSubjectiveDataForComparison/")
getwd()
ld = read.table("../LoudnessData.txt",header=TRUE,sep="\t")
levels(ld1$File) <- c("Dvorak-Fwd","Bach-Prelude","Bjork-IOSQ","Dvorak-Rev","RileyL-","ElliotS-SA")
levels(ld1$Permutation) <- c("-3dB","0dB","6dB","12dB","24dB","Orig") 

ld1= aggregate(SubjectiveData~ Time+File+Permutation, data = ld, mean)
ld2= aggregate(SubjectiveData~ Time+File+Permutation, data = ld, sd)
lddf = as.data.frame(ld1)
lddf2 = as.data.frame(ld2)
lddf$sd = lddf2$SubjectiveData

levels(lddf$File) <- c("Dvorak-Fwd","Bach-Prelude","Bjork-IOSQ","Dvorak-Rev","RLee-San'yo","ElliotS-SA")
levels(lddf$Permutation) <- c("-3dB","0dB","6dB","12dB","24dB","Orig") 

p = ggplot(lddf, aes(Time, SubjectiveData)) + stat_summary(geom="line",fun.y="sd",colour="red")  + xlab("Time (s)") + ylab("Subjective Response") + facet_grid(File~Permutation);
p



d3 = ggplot(lddf, aes(Time, SubjectiveData)) + geom_line() + ylim(0,100) + ylab('Mean Subjective Response +/- 1 Standard Deviation') + geom_ribbon(aes(ymin= SubjectiveData-sd, ymax=SubjectiveData+sd),fill = alpha(colour = "black",2/10),colour = alpha("black",0)) +facet_grid(File~Permutation) +xlab("Time (s)")
d3


# > names(v)
#[1] "Time"         "MeanSubjResp" "STDSubjResp"  "variable"     "value" 

ld1 = subset(ld, variable =="Subject1") 

library(ggplot2)
#[1] "Time"                 "SubjectiveData"       "Loudness"             "AweightedSPL"         "SpectralCtrdThirdOct"  "Filename"             "File"                 "Permutation"          "Preference"           "Familiarity"    
 
 
p = ggplot(subset(ld,File %in% c("File3","File6")), aes(Time, SubjectiveData)) + stat_summary(geom="line",fun.y="sd",colour="red")  + xlab("Time (s)") + ylab("Subjective Response") + facet_grid(File~Permutation);
p

p = ggplot(ld, aes(Time, Loudness)) + stat_summary(geom="line",fun.y="median",colour="red")  + xlab("Time (s)") + ylab("Subjective Response") + facet_grid(File~Permutation,scales="free_y");
p


loud <- xyplot(Loudness ~ Time | File + Permutation, data = ld, type = "l")
subj <- xyplot(median(SubjectiveData) ~ Time | File + Permutation, data = ld, type = "l")

doubleYScale(loud, subj, style1 = 0, style2 = 3, add.ylab2 = TRUE, columns = 3)



names(ld)
p = ggplot(ld,aes(Time,AweightedSPL)) + geom_line() + facet_grid(File~Permutation) +ylim(40,85)
p = ggplot(ld,aes(Time,Loudness)) + geom_line() + facet_grid(File~Permutation) +ylim(0,80)
p = ggplot(ld,aes(Time,SubjectiveData)) + geom_line() + facet_grid(File~Permutation) +ylim(0,80)
p